package com.gjintel.workflow.listener;

import javax.annotation.Resource;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gjintel.business.proj.model.ProjectInfo;
import com.gjintel.business.proj.service.IProjectInfoService;
import com.gjintel.business.proj.service.impl.NotifyServiceImpl;
import com.gjintel.business.proj.service.impl.ProjectInfoServiceImpl;

public class ExecutionListenerInvocation implements ExecutionListener {

	private Expression message;
	
	@Resource
	private IProjectInfoService projectInfoServiceImpl;
	
	@Autowired
	private NotifyServiceImpl notifyService;
	
	@Override
	public void notify(DelegateExecution execution) throws Exception {
		System.out.println("流程："+message.getValue(execution));
		String ms=(String)message.getValue(execution);
		String projectId=execution.getProcessBusinessKey();
		
		ApplicationContext ac = new  ClassPathXmlApplicationContext("classpath*:applicationContext.xml"); 
		projectInfoServiceImpl=(ProjectInfoServiceImpl)ac.getBean("projectInfoServiceImpl");
		
		ProjectInfo project = projectInfoServiceImpl.get(ProjectInfo.class, projectId);
		project.setStatus(Integer.valueOf(ms));
		projectInfoServiceImpl.saveOrUpdate(project);
		
	}




	public void setMessage(Expression message) {
		this.message = message;
	}

}
